layui.extend({
  admin: '{/}../../static/js/admin'
});
layui.use(['laydate', 'jquery', 'admin'], function () {
  var laydate = layui.laydate,
    $ = layui.jquery,
    admin = layui.admin;
  //执行一个laydate实例
  laydate.render({
    elem: '#start' //指定元素
  });
  //执行一个laydate实例
  laydate.render({
    elem: '#end' //指定元素
  });
  /*用户-停用*/
  window.member_stop = function (obj, id) {
    var id = $(obj).parents("tr").attr("data-id")
    if ($(obj).attr('title') == '启用') {
      layer.confirm('确认要停用吗？', function (index) {
        $.get({url: "/role/stop/"+id,async: false})
        $(obj).attr('title', '停用')
        $(obj).find('i').removeClass('layui-icon-download-circle').addClass('layui-icon-upload-circle');
        $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
        layer.msg('已停用!', {
          icon: 5,
          time: 1000
        });
      })
    } else {
      layer.confirm('确认要启用吗？', function (index) {
        $.get({url: "/role/invocation/"+id,async: false})
        $(obj).attr('title', '启用')
        $(obj).find('i').removeClass('layui-icon-upload-circle').addClass('layui-icon-download-circle');
        $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
        layer.msg('已启用!', {
          icon: 6,
          time: 1000
        });
      })
    }
  }

  /*用户-删除*/
  window.member_del = function (obj) {
    layer.confirm('确认要删除吗？', function () {
      var id = $(obj).parent(".td-manage").parent("tr").attr("data-id")
      var nowPage = $(".list").children().length
      //发异步删除数据
      $.get({
        url: "/member/del/"+id,
        success: function(data) {
          $("#memberList").html(data)
        },
        async: false
      })
      var num = parseInt($(".fr>span").html())
      $(".fr>span").html(--num);
      $(obj).parents("tr").remove();
      layer.msg('已删除!', {
        icon: 1,
        time: 1000
      });
    });
  }

  window.delAll = function (argument) {
    var data = admin.tableCheck.getData();
    if (data.length > 0) {
      layer.confirm('确认要删除吗？' + data, function (index) {
        //捉到所有被选中的，发异步进行删除
        layer.msg('删除成功', {
          icon: 1
        });
        $(".layui-form-checked").not('.header').parents('tr').remove();
      });
    } else {
      layer.msg("请先选择");
    }
  }
});